package com.stars.easyms.logger.monitor;

import com.stars.easyms.monitor.MonitorRequestHandler;
import com.stars.easyms.logger.config.EasyMsLoggerHelper;
import com.stars.easyms.logger.constant.EasyMsLoggerConstants;
import com.stars.easyms.logger.support.commons.logging.EasyMsCommonsLog;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * <p>className: EasyMsLoggerMonitorRequestHandler</p>
 * <p>description: EasyMs日志模块的监控方法类</p>
 *
 * @author guoguifang
 * @date 2019-11-20 10:25
 * @since 1.4.0
 */
public final class EasyMsLoggerMonitorRequestHandler implements MonitorRequestHandler {

    private final Log log = LogFactory.getLog(EasyMsLoggerMonitorRequestHandler.class);

    @Override
    public Map<String, Object> getMonitorInfo() {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("重定义", EasyMsLoggerHelper.isRedefineSuccess() ? "成功" : "失败");
        map.put("初始化", EasyMsLoggerHelper.isInitSuccess() ? "成功" : "失败");
        map.put("框架类型", EasyMsLoggerHelper.getLogFrameworkType().getCode());
        String exceptionDesc = EasyMsLoggerHelper.getExceptionDesc();
        if (exceptionDesc != null) {
            map.put("异常描述", exceptionDesc);
        }
        map.put("日志异步", EasyMsLoggerHelper.isLogAsynEnabled() ? "已启动" : "未启动");
        map.put("Sift异步", EasyMsLoggerHelper.isSiftAsynEnabled() ? "已启动" : "未启动");
        map.put("Commons-Logging", (EasyMsLoggerHelper.isLogAsynEnabled() && log instanceof EasyMsCommonsLog) ? "已启动" : "未启动");
        return map;
    }

    @Override
    public String getModuleName() {
        return EasyMsLoggerConstants.MODULE_NAME;
    }

    @Override
    public int getOrder() {
        return 20;
    }

    @Override
    public String getIndexUrl() {
        return EasyMsLoggerConstants.INDEX_URI;
    }
}